package cvgenerator.web;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

/**
 * Class that manipulates the index page.
 * @author Jan Mjartan
 */
public class IndexAction implements ActionBean {
    private String cvId;
    private ActionBeanContext context;
    
    @Override
    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    @Override
    public ActionBeanContext getContext() {
        return context;
    }
    
    /**
     * Redirects to form edit form with a loaded CV if a CV with such id exists.
     * @return Resolution with loaded form.
     */
    public Resolution loadCv() {
        return new ForwardResolution(CvCreateAction.class).addParameter("cvId", cvId);
    }
    
    /**
     * Creates an empty CV and redirects to a form.
     * @return Resolution with empty form.
     */
    public Resolution newCv() {
        return new ForwardResolution(CvCreateAction.class).addParameter("cvId", "new");
    }

    @DefaultHandler
    public Resolution create() {
        return new ForwardResolution("/index.jsp");
    }
    
    public String getCvId() {
        return cvId;
    }

    public void setCvId(String cvId) {
        this.cvId = cvId;
    }
}

   
